package org.macpro.alone.server.contain;

import java.util.List;

import org.macpro.alone.prisist.dao.UserDaoInter;
import org.macpro.alone.prisist.domain.AloneUser;
import org.macpro.alone.server.common.auth.AuthenticateInter;
import org.macpro.alone.server.framework.base.AloneBeanFactory;

public class UserManagerImpl implements UserManagerInter {
	private UserDaoInter userDao;
	/* (non-Javadoc)
	 * @see org.macpro.alone.server.contain.ssss#deleteEntity(java.lang.String)
	 */
	public void deleteEntity(String id) {
		// TODO Auto-generated method stub
		userDao.deleteEntity(userDao.getEntity(id));
	}

	public int getAllListNum() {
		// TODO Auto-generated method stub
		return userDao.getAllListNum();
	}

	/* (non-Javadoc)
	 * @see org.macpro.alone.server.contain.ssss#getEntity(java.lang.String)
	 */
	public AloneUser getEntity(String id) {
		// TODO Auto-generated method stub
		return userDao.getEntity(id);
	}

	/* (non-Javadoc)
	 * @see org.macpro.alone.server.contain.ssss#insertEntity(org.macpro.alone.prisist.domain.AloneUser)
	 */
	public void insertEntity(AloneUser entity) {
		// TODO Auto-generated method stub
		userDao.insertEntity(entity);
	}

	public UserDaoInter getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDaoInter userDao) {
		this.userDao = userDao;
	}

	/* (non-Javadoc)
	 * @see org.macpro.alone.server.contain.ssss#editEntity(org.macpro.alone.prisist.domain.AloneUser)
	 */
	public void editEntity(AloneUser entity) {
		// TODO Auto-generated method stub
		userDao.editEntity(entity);
	}

	public boolean editPassword(String id, String oldPassword,
			String newpassword) {
		// TODO Auto-generated method stub
		return false;
	}

	public String getPassword(String id) {
		// TODO Auto-generated method stub
		AloneUser aloneuser= this.getEntity(id);
		String password=userDao.getPasswordByLoginName(aloneuser.getLoginname()).getPassword();
		return password;
	}

	public boolean isLegality(String loginname, String password) {
		// TODO Auto-generated method stub
		AuthenticateInter authIns=(AuthenticateInter)AloneBeanFactory.getBean("AUTH_ALONE_COMMON");
		String enPassword=authIns.encodeMacpro(password);
		String dataPassword= userDao.getPasswordByLoginName(loginname).getPassword();
		return (enPassword.equals(dataPassword));
	}

	public boolean setInitPassword(String id) {
		// TODO Auto-generated method stub
		return false;
	}

	public List<AloneUser> getAllEntity() {
		// TODO Auto-generated method stub
		return userDao.getAllUser();
	}
}
